<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>长按键入</title>
</head>
<body>
  <script>
    function fn(name, typed) {
      const n = name.length, m = typed.length;
      let i = 0, j = 0;
      while (j < m) {
        if (i < n && name[i] === typed[j]) {
          i++
          j++
        } else if (j > 0 && typed[j] === typed[j - 1]) {
          j++
        } else {
          return false
        }
      }
      return i === n
    }
    console.log(fn('alex', 'aaleex'))
  </script>
</body>
</html>